﻿using Spanner;

namespace SpannerWebSite
{
    internal partial class YourNameInFlashingLights : UI
    {
        internal class BodyHtmlAndInitAct {
            internal Html BodyHtml;
            internal Act InitAct;
        }
        internal static BodyHtmlAndInitAct Content()
        {
            var name = ObsVar<string>("name", "");
            var counter = ObsVar<int>("counter", 0);
            var initAct = Do(SetInterval(Proc(Set(counter, counter + 1)), 750));
            var bodyHtml = Group(
                Style(@"
                    .yellow-lights  { border: 10px dotted yellow; }
                    .red-lights     { border: 10px dotted red; }
                    .blue-lights    { border: 10px dotted blue; }
                    .green-lights   { border: 10px dotted green; }
                "),
                P("Please tell me your name: ", Input().KoValue(name)),
                Div().KoVisible(name != "").WithChildren(
                    P("Your name in flashing lights:").WithAttr("style", "margin-bottom: 40px"),
                    Show(ToUpperCase(name))
                        .WithAttr("style", "font-size: 80px")
                        .WithAttr("style", "margin-left: 40px")
                        .KoCss(CssClassCondition("yellow-lights", counter % 4 == 0),
                               CssClassCondition("red-lights",    counter % 4 == 1),
                               CssClassCondition("green-lights",  counter % 4 == 2),
                               CssClassCondition("blue-lights",   counter % 4 == 3))
                )
            );
            return new BodyHtmlAndInitAct { BodyHtml = bodyHtml, InitAct = initAct };
        }
        internal static void WriteWebPage()
        {
            const string path = Const.DemoWebSitePath;
            var content = Content();
            var html = StandardSpannerHtmlPage("Your name in flashing lights", content.BodyHtml);
            var webPage = WebPage("YourNameInFlashingLights", html, content.InitAct);
            var ctxt = new Context(path);
            ctxt.WriteWebPage(webPage);
        }
    }
}
